public class Half {
    private static int halfLastLowerEqual(int[] arr, int t) {
        return internal(arr, 0, arr.length - 1, t);
    }

    private static int internal(int[] a, int low, int high, int value) {
        if (low > high) return -1;

        int mid = low + (high - low) / 2;

        if (a[mid] > value) {
            high = mid - 1;
            return internal(a, low, high, value);
        } else {
            if ((mid == a.length - 1) || (a[mid + 1] > value)) {
                return mid;
            } else {
                low = mid + 1;
                return internal(a, low, high, value);
            }
        }
    }

    public static void main(String[] args) {
        int[] arr = {-4, 1, 2, 2, 5, 5, 5, 8, 10};
        int value = 6;
        int res = halfLastLowerEqual(arr, value);
        System.out.println("小于等于" + value + " 的数组下标为=" + res);
    }
}